/**
 * Created by ${PRODUCT_NAME}.
 * User: sbusse
 * Date: 11.02.11
 * Time: 11:47
 * To change this template use File | Settings | File Templates.
 */
package generalUsageTests.tests {
	import de.ghost23.common.process.Process;

	import de.ghost23.common.process.ProcessEvent;

	import flash.utils.getDefinitionByName;

	import org.flexunit.Assert;
	import org.flexunit.async.Async;

	public class BasicProcessTests {

		private var sampleProcess:Process;
		private var asyncHandlerSuccess:Function;

		public function BasicProcessTests() {

		}

		[Before]
		public function runBeforeEveryTest():void {

			// sample code
			sampleProcess = new Process();
			sampleProcess.pushCommand(SampleCommand);
			sampleProcess.pushCommand(SampleCommand);
			sampleProcess.pushCommand(SampleCommand);
		}

		private function onProcessCompleted(event:ProcessEvent, data:Object) : void {
			Assert.assertEquals("Complete event contains SampleCommand", getDefinitionByName("generalUsageTests.tests.SampleCommand"), event.command);
		}

		private function onProcessTimeout(data:Object):void {

		}

		[After]
		public function runAfterEveryTest():void {

			sampleProcess.removeEventListener(ProcessEvent.COMPLETED, asyncHandlerSuccess);
			sampleProcess.clear();
			sampleProcess = null;
		}

		[Test(async, description="Basic StateMachine tests!")]
		public function testDijkstra():void {

			asyncHandlerSuccess = Async.asyncHandler(this, onProcessCompleted, 500, null, onProcessTimeout);
			Async.registerFailureEvent(this, sampleProcess, ProcessEvent.FAILED);

			sampleProcess.addEventListener(ProcessEvent.COMPLETED, asyncHandlerSuccess, false, 0, true);
			sampleProcess.start();
		}
	}
}
